﻿namespace Whut.ObjectSharePointMapper
{
    using System;

    public struct Lookup : IEquatable<Lookup>
    {
        private int id;

        private string value;

        public Lookup(int id)
        {
            this.id = id;
            this.value = null;
        }

        public Lookup(int id, string value)
        {
            this.id = id;
            this.value = value;
        }

        public int Id
        {
            get
            {
                return this.id;
            }

            private set
            {
                this.id = value;
            }
        }

        public string Value
        {
            get
            {
                return this.value;
            }

            private set
            {
                this.value = value;
            }
        }

        public static bool operator ==(Lookup lookup1, Lookup lookup2)
        {
            return lookup1.Equals(lookup2);
        }

        public static bool operator !=(Lookup lookup1, Lookup lookup2)
        {
            return !lookup1.Equals(lookup2);
        }

        public override bool Equals(object obj)
        {
            if (!(obj is Lookup))
            {
                return false;
            }

            return this.Equals((Lookup)obj);
        }

        public bool Equals(Lookup other)
        {
            return this.id == other.id && this.value == other.value;
        }

        public override int GetHashCode()
        {
            return this.id ^ this.value.GetHashCode();
        }

        public override string ToString()
        {
            return this.id + ";#" + this.value;
        }

        public static implicit operator Lookup(int id)
        {
            return new Lookup(id);
        }
    }
}
